{{ $figcap := or .Title }}
{{ $caption := or .Text " " }}
{{ $alt := or .Text $figcap }}
{{- if eq $figcap $caption -}}
{{ $caption = " " }}
{{- end -}}
{{ $imageOriginal := .Page.Resources.GetMatch (printf "%s" (.Destination | safeURL)) }}
{{ if $imageOriginal }}
{{ if lt 1600 $imageOriginal.Width }}
{{ $imageOriginal = ($imageOriginal.Resize "1600x q100").Permalink }}
{{ end }}
{{ else }}
{{ $imageOriginal = .Destination }}
{{ end }}
{{- if $figcap -}}
<figure>
    {{- dict "Src" $imageOriginal "Title" $figcap "Alt" $alt "Caption" $caption "Linked" true "Resources" .Page.Resources | partial "plugin/image.html" -}}
    <figcaption class="image-caption">
        {{- $figcap | safeHTML -}}
    </figcaption>
</figure>
{{- else -}}
{{- dict "Src" $imageOriginal "Title" (path.Base .Destination) "Alt" $alt "Resources" .Page.Resources | partial "plugin/image.html" -}}
{{- end -}}